package com.unionfetch.content_home.api

import com.unionftech.baselibrary.network.RetrofitClient

class HomeApiManager private constructor() {
    private lateinit var mAccountApi: AccountApi
    private lateinit var mHomeApi: HomeApi
    private lateinit var mOpenAccountApi: OpenAccountApi
    private lateinit var mKYCApi: KYCApi

    companion object {
        @Volatile
        private var mInstance: HomeApiManager? = null

        @JvmStatic
        fun getInstance() = mInstance ?: synchronized(HomeApiManager::class.java) {
            mInstance ?: HomeApiManager().also {
                mInstance = it
            }
        }
    }

    fun apiAccount(): AccountApi {
        if (!::mAccountApi.isInitialized) {
            mAccountApi = RetrofitClient.getInstance().create(AccountApi::class.java)
        }
        return mAccountApi
    }

    fun apiHome(): HomeApi {
        if (!::mHomeApi.isInitialized) {
            mHomeApi = RetrofitClient.getInstance().create(HomeApi::class.java)
        }
        return mHomeApi
    }

    fun apiOpenAccount(): OpenAccountApi {
        if (!::mOpenAccountApi.isInitialized) {
            mOpenAccountApi = RetrofitClient.getInstance().create(OpenAccountApi::class.java)
        }
        return mOpenAccountApi
    }

    fun apiKYC(): KYCApi {
        if (!::mKYCApi.isInitialized) {
            mKYCApi = RetrofitClient.getInstance().create(KYCApi::class.java)
        }
        return mKYCApi
    }
}